#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int y11[2076] = {0};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
int month_leap[]={31,29,31,30,31,30,31,31,30,31,30,31};

bool isrun(int year){
    if(year%400==0||(year%4==0&&year%100!=0))return true;
    return false;
}

void solve(){
    int k,l,r;
    cin>>k>>l>>r;
    vector<int> add(366,0);
    
    for (int y = l; y <= r; y++) {
        int day=0;
        int* mdays = isrun(y) ? month_leap : month;
        for(int m=0;m<12;m++){
            for(int d=1;d<=mdays[m];d++,day++){
                int weekday = (day + y11[y]) % 7;
                if(weekday >=1 && weekday <=5){ // Monday to Friday
                    add[day]++;
                }
            }
        }
    }
    sort(add.begin(),add.end());
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=add[i];
    }
    cout<<sum<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    // 2025-01-01 is Wednesday (3)
    y11[2025] = 3;
    for (int y = 2026; y <= 2075; ++y) {
        y11[y] = (y11[y-1] + (isrun(y-1)?366:365)) % 7;
    }

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}